home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / e_to_l / gclipbrd / demo1.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  2KB  |  90 lines

  1. unit Demo1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils,
  7.   {$IFDEF Win32}
  8.   Windows,
  9.   {$ELSE}
  10.   WinTypes, WinProcs,
  11.   {$ENDIF}
  12.   Messages, Classes, Graphics, Controls,
  13.   Forms, Dialogs, ExtCtrls, Grids;
  14.  
  15. type
  16.   TClipboardDemo = class(TForm)
  17.     StringGrid1: TStringGrid;
  18.     Panel1: TPanel;
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure StringGrid1DrawCell(Sender: TObject; aCol, aRow: Longint;
  21.       Rect: TRect; State: TGridDrawState);
  22.     procedure FormResize(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.     Procedure UpdateClipboardDisplay (Sender: TObject);
  26.   public
  27.     { Public declarations }
  28.   end;
  29.  
  30. var
  31.   ClipboardDemo: TClipboardDemo;
  32.  
  33. implementation
  34.  
  35. {$R *.DFM}
  36.  
  37. Uses gClipBrd;
  38.  
  39. procedure TClipboardDemo.FormCreate(Sender: TObject);
  40. begin
  41.   Clipboard.OnChange := UpdateClipboardDisplay;
  42.   StringGrid1.Cells [0, 0] := 'Size';
  43.   StringGrid1.Cells [1, 0] := 'Name';
  44.   UpdateClipboardDisplay (Sender);
  45. end;
  46.  
  47. Procedure TClipboardDemo.UpdateClipboardDisplay (Sender: TObject);
  48. var
  49.   I:   Integer;
  50. begin
  51.   With Clipboard do begin
  52.     Open;
  53.     If HasFormat (cf_Text)
  54.       Then Panel1.Caption := AsText
  55.       Else Panel1.Caption := '';
  56.     StringGrid1.RowCount := FormatCount + 1;
  57.     For I := 0 to FormatCount - 1 do begin
  58.       StringGrid1.Cells [0, I + 1] := IntToHex (GlobalSize (GetAsHandle (Formats[I])),5);
  59.       StringGrid1.Cells [1, I + 1] := FormatNames [I];
  60.       end;
  61.     Close;
  62.     end;
  63.   end;
  64.  
  65. procedure TClipboardDemo.StringGrid1DrawCell(Sender: TObject; aCol,
  66.   aRow: Longint; Rect: TRect; State: TGridDrawState);
  67. begin
  68.   With StringGrid1 do begin
  69.     If aRow < FixedRows
  70.       Then Canvas.Brush.Color := clBtnFace
  71.       Else Canvas.Brush.Color := Color;
  72.     Canvas.FillRect (Rect);
  73.     Case aCol of
  74.       0:
  75.         Canvas.Textout (Rect.Right - Canvas.TextWidth (Cells[aCol, aRow]) - 4,
  76.                         Rect.Top, Cells [aCol, aRow]);
  77.       1:
  78.         Canvas.Textout (Rect.Left + 2, Rect.Top, Cells [aCol, aRow]);
  79.       end;
  80.     end;
  81.   end;
  82.  
  83. procedure TClipboardDemo.FormResize(Sender: TObject);
  84. begin
  85.   With StringGrid1 do
  86.     ColWidths[1] := ClientWidth - ColWidths [0];
  87. end;
  88.  
  89. end.
  90.